package com.yxinsur.imc.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yxinsur.imc.business.domain.ImcOrderRisk;
import com.yxinsur.imc.business.domain.ImcRecnDetails;
import com.yxinsur.imc.business.domain.ImcRenewalRecnDetails;
import com.yxinsur.imc.business.fact.OrderRiskInfoFact;
import com.yxinsur.imc.business.fact.OrderRiskInfoNowFact;
import com.yxinsur.imc.business.form.RenewalOrderSearchForm;
import com.yxinsur.imc.business.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 保单险种详情Mapper接口
 *
 * @author imc
 * @date 2021-03-18
 */
@Mapper
public interface ImcOrderRiskMapper extends BaseMapper<ImcOrderRisk> {
    /**
     * 批量更新[order_risk]表
     *
     * @param imcOrderRiskList ImcOrderRisk集合
     * @return 结果
     */
    int updateImcOrderRiskListOfRecn(@Param("list") List<ImcOrderRisk> imcOrderRiskList);

    /**
     * 根据保单ID查询保单险种记录
     *
     * @param orderId
     * @return
     */
    List<OrderRiskVo> selectOrderRisksList(@Param("orderId") Long orderId, @Param("isRenewal") Integer isRenewal, @Param("tenantId") Long tenantId, @Param("param") RenewalOrderSearchForm param);

    /**
     * 根据{ID}查询保单险种记录
     *
     * @param id ID
     * @return 结果
     */
    ImcOrderRisk getImcOrderRiskById(@Param("id") Long id);

    /**
     * 获得指定代理人的指定月份保单
     *
     * @param brokerId
     * @return
     */
    OrderRiskInfoFact selectOrderRiskInfoFact(@Param("brokerId") Long brokerId, @Param("pastCaliber") String pastCaliber, @Param("pastStart") Date pastStart, @Param("pastEnd") Date pastEnd);

    /**
     * 获得指定代理人当月结算保单[新契约]
     *
     * @param brokerId
     * @return
     */
    List<OrderRiskInfoNowFact> selectOrderRiskInfoNowList(@Param("brokerId") Long brokerId, @Param("settleMonth") String settleMonth);


    /**
     * 根据代理人 基本法口径 获得order_risk信息
     *
     * @param brokerIds
     * @param sqlParam
     * @param tenantId
     * @return
     */
    List<OrderRiskToCommRiskVo> selectOrderRiskToCommRiskList(@Param("brokerIds") List<Long> brokerIds, @Param("sqlParam") String sqlParam, @Param("tenantId") Long tenantId);

    List<OrderRiskToCommRiskVo> selectOrderRiskToCommRisk(Long orderRiskId);

    /**
     * 新增保单查询
     *
     * @param policyCode
     * @param tenantId
     * @return
     */
    List<CommRiskVo> commOrder(@Param("policyCode") String policyCode, @Param("tenantId") Long tenantId, @Param("orderRiskId") Long orderRiskId, @Param("commId") Long commId);


    /**
     * 反结将paymonth状态置空
     *
     * @param imcOrderRisk
     */
    void updateOrderRiskPayMonth(ImcOrderRisk imcOrderRisk);

    /**
     * 根据{条件}查询OrderRisk表数据条数
     *
     * @param criteriaSQL 条件字符串
     * @return OrderRisk表数据条数
     */
    ImcOrderRisk getOrderRiskByCriteria(@Param("criteriaSQL") String criteriaSQL);

    BigDecimal selectYearStandPremByPastCaliberAndBrokerId(@Param("brokerId") Long brokerId, @Param("pastCaliber") String pastCaliber, @Param("applyDateStart") Date applyDateStart, @Param("applyDateEnd") Date applyDateEnd, @Param("tenantId") Long tenantId);

    /**
     * 根据{机构}{险种}{协议费用科目表达式}{协议费用科目ID}查询[order_risk]表
     *
     * @param orgIdList         机构ID集合
     * @param repoInsIdList     险种ID集合
     * @param criteriaSql       协议费用科目表达式
     * @param contractExpenseId 协议费用科目ID
     * @param tenantId          租户ID
     * @return 结果
     */
    List<ImcRecnDetails> listRecnOrderRiskList(@Param("orgIdList") List<Long> orgIdList, @Param("repoInsIdList") List<Long> repoInsIdList, @Param("criteriaSQL") String criteriaSql, @Param("contractExpenseId") long contractExpenseId, @Param("tenantId") long tenantId);

    /**
     * 根据{机构}{协议费用科目表达式}{协议费用科目ID}查询[order_risk]表
     *
     * @param orgIdList         机构ID集合
     * @param criteriaSql       协议费用科目表达式
     * @param contractExpenseId 协议费用科目ID
     * @param tenantId          租户ID
     * @return 续期手续费险种记录
     */
    List<ImcRenewalRecnDetails> listRenewalRecnOrderRiskList(@Param("orgIdList") List<Long> orgIdList, @Param("criteriaSQL") String criteriaSql, @Param("contractExpenseId") long contractExpenseId, @Param("tenantId") long tenantId);

    List<PersistencyOrderRiskVo> selectPerisitencyOrderByQueryMap(@Param("queryMap") HashMap<String, Object> queryMap, @Param("tenantId") Long tenantId);

    ImcOrderRisk getOrderRiskByOrderIdAndRepoInsId(@Param("orderId") Long orderId, @Param("repoInsId") Long repoInsId, @Param("tenantId") Long tenantId);

    List<DenominatorOrderVo> selectOrderRiskByDeno(@Param("orderRiskIdList") ArrayList<String> orderRiskIdList);

    List<OrderRiskToCommRiskVo> selectOrderRiskBySqlParam(@Param("criteriaSQL") String criteriaSQL, @Param("tenantId") Long tenantId);
}
